package com.example.demo.controller;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.dao.UserRoleRepository;
import com.example.demo.entity.Student;
import com.example.demo.entity.UserRole;

// 标识为控制器类
@RestController
public class FirstController {
    private final UserRoleRepository userRoleRepository;

    // @Autowired
    public FirstController(UserRoleRepository userRoleRepository) {
        this.userRoleRepository = userRoleRepository;
        // Spring管理的对象，不要通过new创建 this.userRoleRepository = new ...
    }

    @GetMapping("/say-hello")
    public String sayHello() {
        return "Hello World!";
    }

    @GetMapping("/students")
    public List<Student> getStudents() {
        return Arrays.asList(
            new Student("001", "张三", "男", "zhangsan@163.com"),
            new Student("002", "李四", "女", "lisi@163.com"),
            new Student("003", "王五", "男", "wangwu@163.com")
        );
    }
}
